home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / common / listwnd.h < prev    next >
C/C++ Source or Header  |  2001-10-08  |  9KB  |  295 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. #ifndef _LISTWND_H
  30. #define _LISTWND_H
  31.  
  32. #include "scbkgwnd.h"
  33. #include "common.h"
  34.  
  35. #include "string.h"
  36. #include "freelist.h"
  37.  
  38. #define POS_LAST -1
  39.  
  40. #define LISTWND_PARENT ScrlBkgWnd
  41.  
  42. #define LW_HT_DONTKNOW    (-1)
  43. #define LW_HT_ABOVE    (-10)
  44. #define LW_HT_BELOW    (-20)
  45.  
  46. class listItem;
  47. class ListWnd;
  48. class CompareListItem;
  49.  
  50. class COMEXP ListColumn : public Named {
  51. friend ListWnd;
  52. public:
  53.   ListColumn(const char *name=NULL);
  54.  
  55.   int getWidth();
  56.   void setWidth(int newwidth);
  57.   const char *getLabel();
  58.   void setLabel(const char *newlabel);
  59.   virtual int customDrawHeader(Canvas *c, RECT *cr);
  60.   int getNumeric() { return numeric; }
  61.  
  62.   void setDynamic(int isdynamic);
  63.   int isDynamic() { return dynamic; }
  64.  
  65. protected:  
  66.   void setIndex(int i);
  67.   int getIndex();
  68.   void setList(ListWnd *list);
  69.   ListWnd *getList();
  70.   void setNumeric(int n) { numeric=n; }
  71.  
  72. private:
  73.   int width;
  74.   int index;
  75.   int numeric;
  76.   int dynamic;
  77.   ListWnd *list;
  78. };
  79.  
  80. class SelItemList;
  81.  
  82. class COMEXP ListWnd : public ScrlBkgWnd {
  83. friend ListColumn;
  84. friend SelItemList;
  85. public:
  86.   ListWnd();
  87.   virtual ~ListWnd();
  88.  
  89.   virtual int onInit();
  90.   virtual int onPaint(Canvas *canvas);
  91.   virtual int onResize();
  92.   virtual int onLeftButtonDown(int x, int y);
  93.   virtual int onLeftButtonUp(int x, int y);
  94.   virtual int onRightButtonDown(int x, int y);
  95.   virtual int onRightButtonUp(int x, int y);
  96.   virtual int onMouseMove(int x, int y);
  97.   virtual int onLeftButtonDblClk(int x, int y);
  98.   virtual int onChar(char c);
  99.   virtual int onKeyDown(int keyCode);
  100.   virtual int onContextMenu (int x, int y);
  101.   virtual int onMouseWheelUp(int click, int lines);
  102.   virtual int onMouseWheelDown(int click, int lines);
  103.  
  104.   void onSetVisible(int show);
  105.  
  106.   void setAutoSort(BOOL dosort);
  107.   void setOwnerDraw(BOOL doownerdraw);
  108.  
  109.   void next();
  110.   void previous();
  111.   void pagedown();
  112.   void pageup();
  113.   void home();
  114.   void end();
  115.   
  116.   void setItemCount(int c);
  117.   void reset();
  118.   int addColumn(const char *name, int width, int numeric=0);    // adds to end
  119.   ListColumn *getColumn(int n);
  120.   int getNumColumns();
  121.   int getColumnWidth(int col);
  122.   void setRedraw(BOOL redraw);
  123.   BOOL getRedraw();
  124.   virtual int addItem(char *label, LPARAM lParam);
  125.   virtual int insertItem(int pos, char *label, LPARAM lParam);
  126.   virtual int getLastAddedItemPos();
  127.   virtual void setSubItem(int pos, int subpos, char *txt);
  128.   virtual void deleteAllItems();
  129.   virtual int deleteByPos(int pos);
  130.   int getNumItems(void);
  131.   virtual int getItemLabel(int pos, int subpos, char *text, int textmax);
  132.   virtual void setItemLabel(int pos, char *text);
  133.   virtual LPARAM getItemData(int pos);
  134.   virtual int getItemRect(int pos, RECT *r);
  135.   virtual int getItemSelected(int pos);    // returns 1 if selected
  136.   virtual int getItemFocused(int pos);    // returns 1 if focused
  137.   virtual int getItemFocused();         // returns focused item
  138.   void ensureItemVisible(int pos);
  139.   virtual int scrollAbsolute(int x);
  140.   virtual int scrollRelative(int x);
  141.   virtual const char *getSubitemText(int pos, int subpos);
  142.   virtual int getFirstItemSelected();
  143.  
  144.   virtual int selectAll();    // force all items selected
  145.   virtual int deselectAll(); // force all items to be deselected
  146.   virtual int invertSelection();    // invert all selections
  147.  
  148.   virtual int hitTest(POINT pos);
  149.   virtual int hitTest(int x, int y);
  150.   virtual int invalidateItem(int pos);
  151.   virtual int locateData(LPARAM data);
  152.  
  153.   // -1 if we've never been drawn yet
  154.   int getFirstItemVisible() const { return firstItemVisible; }
  155.   int getLastItemVisible() const { return lastItemVisible; }
  156.  
  157.   virtual int setFontSize(int size);
  158.   virtual int getFontSize();
  159.   virtual void jumpToNext(char c);
  160.   int wantFocus() { return 1; }
  161.  
  162.   void scrollToItem(int pos);
  163.  
  164.   virtual void resort();
  165.   int getSortDirection();
  166.   int getSortColumn();
  167.   void setSortColumn(int col);
  168.   void setSortDirection(int dir);
  169.   int findItemByParam(LPARAM param);
  170.   void setItemParam(int pos, LPARAM param);
  171.   int getItemCount() { return getNumItems(); }
  172.  
  173.   void setSelectionStart(int pos);
  174.   void setSelectionEnd(int pos);
  175.   void setSelected(int pos, int selected);
  176.   void toggleSelection(int pos, int setfocus=TRUE);
  177.  
  178.   virtual int getHeaderHeight();
  179.  
  180.   // this sort function just provides string/numeric comparison
  181.   // if you need more types, just override and provide your own
  182.   virtual int sortCompareItem(listItem *p1, listItem *p2);
  183.   
  184. protected:
  185.   // return 1 if you override this
  186.   virtual int ownerDraw(Canvas *canvas, int pos, RECT *r, LPARAM lParam, int selected, int focused) { return 0; };
  187.  
  188.   virtual void onPreItemDraw(Canvas *canvas, int pos, RECT *r, LPARAM lParam, int selected, int focused) { }
  189.   virtual void onPostItemDraw(Canvas *canvas, int pos, RECT *r, LPARAM lParam, int selected, int focused) { };
  190.   virtual COLORREF getTextColor(LPARAM lParam);
  191.   virtual COLORREF getSelBgColor(LPARAM lParam);
  192.   virtual COLORREF getBgColor();
  193.   virtual COLORREF getFocusColor(LPARAM lParam);
  194.  
  195. public:
  196.   int insertColumn(ListColumn *col, int pos=-1);// -1 is add to end
  197.  
  198. protected:
  199.   int getColumnsHeight();
  200.   int getColumnsWidth();
  201.   int getContentsWidth();
  202.   int getContentsHeight();
  203.   virtual void drawBackground(Canvas *canvas);
  204.   void drawColumnHeaders(Canvas *c);
  205.   void drawItems(Canvas *canvas);
  206.   void updateScrollX();
  207.   void updateScrollY();
  208.   int doJumpToNext(char c, BOOL fromTop);
  209.   int fullyVisible(int pos);
  210.  
  211.   virtual int onBeginDrag(int iItem);
  212.  
  213.   virtual void onSelectAll();    // hit Control-A
  214.   virtual void onDelete();        // hit 'delete'
  215.   virtual void onItemDelete(LPARAM lparam) {}
  216.   virtual void onDoubleClick(int itemnum);    // double-click on an item
  217.   // this is called with the selected item#
  218.   virtual void onLeftClick(int itemnum);    // left-click
  219.   // the second time you click on an already-focused item
  220.   virtual void onSecondLeftClick(int itemnum);
  221.   // return 1 if you want more callbacks with the rest of the items
  222.   virtual int onRightClick(int itemnum);    // right-click on item
  223.  
  224.   // override this to be notified of item selections & deselections
  225.   virtual void onItemSelection(int itemnum, int selected) {}
  226.  
  227.   virtual int onColumnDblClick(int col, int x, int y) { return 0; }
  228.   virtual int onColumnLabelClick(int col, int x, int y);
  229.  
  230.   void selectRect(int x1, int y1, int x2, int y2);
  231.   void drawRect(int x1, int y1, int x2, int y2);
  232.  
  233.   // interface to Freelist
  234.   listItem *createListItem();
  235.   void deleteListItem(listItem *item);
  236.  
  237.   ListColumn *enumListColumn(int pos);
  238.   int getColumnPosByName(const char *name);
  239.   int delColumnByPos(int pos);
  240.  
  241. protected:
  242.   BOOL showColumnsHeaders;
  243.  
  244.   void recalcHeaders();
  245.  
  246. private:
  247.   int doAddItem(char *label, LPARAM lParam, int pos);
  248.   int hitTestColumns(POINT p, int *origin=NULL);
  249.   int hitTestColumnsLabel(POINT p);
  250.   void drawXorLine(int x);
  251.   void calcNewColWidth(int col, int x);
  252.   void calcBounds();
  253.  
  254.   int autosort, ownerdraw;
  255.   int textsize;
  256.     int itemHeight;
  257.     BOOL metrics_ok;
  258.     BOOL redraw;
  259.     int columnsHeight;
  260.  
  261.     PtrList<ListColumn> columnsList;
  262.     PtrListQuickSorted<listItem,CompareListItem> itemList;
  263.  
  264.     int firstItemVisible;
  265.     int lastItemVisible;
  266.  
  267.     listItem *lastItemFocused;
  268.     int lastItemFocusedPos;
  269.  
  270.     listItem *lastAddedItem;
  271.   SelItemList *selItemList;
  272.  
  273.     int selectionStart;
  274.     int colresize;
  275.     POINT colresizept;
  276.     BOOL resizing_col;
  277.     int colresizeo;
  278.  
  279.     BOOL processbup;
  280.     BOOL bdown;
  281.     BOOL nodrag;
  282.   int bdownx, bdowny;
  283.     BOOL firstComplete, lastComplete;
  284.  
  285.     int rectselecting;
  286.     POINT selectStart;
  287.     POINT selectLast;
  288.  
  289.   int sortdir, sortcol, lastcolsort;
  290.     
  291.   Freelist<listItem> listItem_freelist;
  292. };
  293.  
  294. #endif
  295.